// pages/index/process/process.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    process: [],
    retreat: '', //退
    exchange: '', //换
    currentUserId: '', //已选中的顶部用户id
    // id: JSON.parse(wx.getStorageSync('app_user_info')).id,  //当前登陆人id
    id: '', //当前登陆人id

    userList: [], //员工列表
    LookingSpot: '' //找现货
    // a:getApp().globalData
  },
  //输入工单号
  import(e) {
    console.log(e)
    let process = e.currentTarget.dataset.item.isLast == 2 && e.currentTarget.dataset.item.type == 1 ? 0 : 1
    wx.navigateTo({
      url: `../workordernumber/workordernumber?id=${e.currentTarget.dataset.item.id}&&process=${process}&from=1`,
    })
  },
  handleClickTop(e) {
    this.setData({
      currentUserId: e.currentTarget.dataset.userid
    })
    // 将选中的userId存储起来
    wx.setStorageSync('currentUserId', e.currentTarget.dataset.userid)
    // console.log(e, this.data.currentUserId)
    this.getTypeWork()
  },
  //退换货输入工号单
  ChangingorRefunding(e) {
    // console.log(type)
    wx.navigateTo({
      url: `../workordernumber/workordernumber?process=0&&id=null&&type=${e.currentTarget.dataset.type}`,
    })
  },
  async getTypeWork() {
    this.setData({
      loading: true,
      process: []
    })
    var data = await global.$api.post({
      url: 'api/userInfo/getMyOccupationProcessByProcessType',
      data: {
        userId: this.data.currentUserId,
        type: 1
      }
    })
    if (data.code == 200) {
      this.setData({
        process: data.data,
        loading: false,
      })
      console.log('这是数据', data.data)
    }
  },
  //扫描工单号
  scan(e) {
    let process = e.currentTarget.dataset.item.isLast == 2 && e.currentTarget.dataset.item.type == 1 ? 0 : 1
    wx.navigateTo({
      url: `../scan/scan?type=1&&id=${e.currentTarget.dataset.item.id}&&process=${process}&from=1`,
    })
  },

  //扫描退换货
  ScanChangingorRefunding(e) {
    wx.navigateTo({
      url: `../scan/scan?type=1&&id=null&&process=null&&way=${e.currentTarget.dataset.type}`,
    })
  },
  async getUserInfo() {
    await global.$cacheHelper.getUerInfo()
    await this.setData({
      // a:getApp().globalData
      retreat: getApp().globalData.retreat,
      exchange: getApp().globalData.exchange,
      LookingSpot: getApp().globalData.LookingSpot
    })
  },
  // 获取顶部员工列表
  async getUserList() {
    var data = await global.$api.pbpost({
      url: 'api/skirt/getGroupUserList',
      data: {}
    })
    if (data.code == 200) {
      this.setData({
        userList: data.data,
        currentUserId: data.data[0].userId
      })
      // 将选中的userId存储起来
      wx.setStorageSync('currentUserId', data.data[0].userId)
      this.getTypeWork()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: JSON.parse(wx.getStorageSync('app_user_info')).id
    })
    this.getUserList()
    this.getUserInfo()
    // global.$cacheHelper.getUerInfo()
    // // global.$cacheHelper.updateUserInfo()
    // console.log(getApp().globalData)
    // this.setData({
    //   // a:getApp().globalData
    //   retreat:getApp().globalData.retreat,
    //   exchange:getApp().globalData.exchange
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.removeStorageSync('currentUserId')
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})